/*
 * Aleatorio.java
 *
 * Created on 19 de junio de 2005, 23:26
 */

package akaram.util;

/**
 *
 * Clase de manejo de la aleatoriedad
 *
 * @author Mel Hython
 */
public class Aleatorio {
    
   /**
    *
    * Da un valor entre dos enteros
    *
    */
   static public int
   numEntre( int min, int max )
   {
       if ( min >= max )
           return max;
       
       int dist = max - min;
       
       int off = (int)Math.round( Math.floor( (Math.random())*(double)(dist+1) ));
       
       return min + off;
   }
   
   static public long
   numEntre( long min, long max )
   {
       if ( min >= max )
           return max;
       
       long dist = max - min;
       
       long off = (long)Math.round( Math.floor( (Math.random())*(double)(dist+1) ));
       
       return min + off;
   }
   
   public static void
   main( String args[] )
   {
       System.out.println( "0-100: " + Aleatorio.numEntre(0,100) );
       System.out.println( "25-50: " + Aleatorio.numEntre(25,50) );
       System.out.println( "1-6: " + Aleatorio.numEntre(1,6) );
       System.out.println( "1-20: " + Aleatorio.numEntre(1,20) );
       System.out.println( "3-7: " + Aleatorio.numEntre(3,7) );   
       
       int[] val = new int[101];
       
       for( int i = 0; i < 101; i++ )
       {
           val[i] = 0;
       }
       
       for( int i = 0; i < 10000; i++ )
       {
           val[Aleatorio.numEntre(0,100)]++;
       }
       
       for( int i = 0; i < 101; i++ )
       {
           System.out.print(val[i]);
           System.out.print(';');
       }       
       System.out.println("");
   }
    
}
